<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>嵌套路由</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="../js/vue-router.min.js"></script>

</head>
<body>
<div id="app">
    <router-link to="/user">User</router-link>
    <router-link to="/login">Login</router-link>
    <router-view></router-view>
</div>
<script type="text/javascript">
    var User = { template:"<div>This is User</div>" }
    //Login组件中的模板代码里面包含了子级路由链接以及子级路由的占位符  子路由组件将会在router-view中显示
    var Login = { template: `<div>
        <h1>This is Login</h1>
        <hr>
        <router-link to="/login/account">账号密码登录</router-link>
        <router-link to="/login/phone">扫码登录</router-link>
         <router-view></router-view>
          </div>`
    }
    //定义两个子级路由组件
    var account = { template:"<div>账号：<input><br>密码：<input></div>"};
    var phone = { template:"<h1>扫我二维码</h1>"};

    var router=new VueRouter({
        routes:[
            { path:"/",redirect:"/user"},
            {path:'/user',component:User},
            {path:'/login',component:Login,
                //通过children属性为/login添加子路由规则
                children:[
                    { path: "/login/account", component: account },
                    { path: "/login/phone", component: phone },
                ]
            },
        ]
    })

    var vm=new Vue({
        el:'#app',
        router
    })
</script>
</body>
</html>